package org.smartopen.unionpay.openapi.config;

import lombok.RequiredArgsConstructor;
import org.smartopen.unionpay.openapi.aspect.OpenApiAspect;
import org.smartopen.unionpay.openapi.component.UnionPayOpenApiProperties;
import org.smartopen.unionpay.openapi.constant.UnionPayConstant;
import org.smartopen.unionpay.openapi.service.UnionPayService;
import org.smartopen.unionpay.openapi.service.feigin.RemoteUnionPayOpenApiService;
import org.smartopen.unionpay.openapi.service.impl.UnionPayServiceImpl;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;

@EnableConfigurationProperties({UnionPayOpenApiProperties.class})
@RequiredArgsConstructor
@Configuration
@EnableFeignClients(basePackages = UnionPayConstant.BASE_PACKAGE)
@ComponentScan(UnionPayConstant.BASE_PACKAGE)
public class UnionPayAutoConfiguration {

    @Bean
    public OpenApiAspect openapiAspect(UnionPayOpenApiProperties openApiProperties) {
        return new OpenApiAspect(openApiProperties);
    }

    @Bean
    @ConditionalOnMissingBean
    public UnionPayService unionPayServiceImpl(RemoteUnionPayOpenApiService openApiService) {
        return new UnionPayServiceImpl(openApiService);
    }

}